Fred Hutch Data Science Lab (DaSL)
Shiny is an R package that makes it easy to build interactive web apps straight from R. No knowledge of HTML, CSS, or JavaScript is required. But, it is fully customizable and extensible with HTML/CSS/JavaScript. Shiny lets you write R code to create web applications.
library(shiny)
# Define UI for app that draws a histogram
ui <- fluidPage(
# App title
titlePanel("Hello Shiny!"),
# Sidebar layout with input and output definitions
sidebarLayout(
# Sidebar panel for inputs
sidebarPanel(
# Input: Slider for the number of bins
sliderInput(inputId = "bins",
label = "Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Main panel for displaying outputs
mainPanel(
# Output: Histogram
plotOutput(outputId = "distPlot")
)
)
)
# Define server code required to draw a histogram
server <- function(input, output) {
# Histogram of the Old Faithful Geyser Data
# with requested number of bins
# Code that generates a histogram is wrapped in a call
# to renderPlot.
output$distPlot <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = "#007bc2", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
}
# Create shiny app
shinyApp(ui = ui, server = server)tabsetPanel()navListPanel()Missing parenthesis, commas, and typos
library(shiny)
# Define UI for app that draws a histogram
ui <- fluidPage(
# App title
titlePanel("Hello Shiny!"),
# Sidebar layout with input and output definitions
sidebarLayout(
# Sidebar panel for inputs
sidebarPanel(
# Input: Slider for the number of bins
sliderInput(inputId = "bins",
label = "Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Main panel for displaying outputs
mainPanel(
# Output: Histogram
plotOutput(outputId = "distPlot")
)
)
)
# Define server code required to draw a histogram
server <- function(input, output) {
# Histogram of the Old Faithful Geyser Data
# with requested number of bins
# Code that generates a histogram is wrapped in a call
# to renderPlot.
output$distPlot <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = "#007bc2", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
}
# Create shiny app
shinyApp(ui = ui, server = server)Baltimore Community Data Science (PH.140.801 + 802)